import java.util.*;

public class Work03 {
    static String init;
    static String target;

    static int[] direction = {-3,-2,-1,1,2,3};

    static void bfs(){
        Queue<String> que = new LinkedList<String>();
        Set<String> set = new HashSet<String>();
        que.add(init);
        set.add(init);
        int count = 0;
        while(!que.isEmpty()){
            int size = que.size();
            for (int i = 0; i < size; i++) {
                String tmp = que.poll();
                System.out.println(tmp);
                assert tmp != null;
                if(tmp.equals(target)){
                    System.out.println(count);
                    return;
                }
                int index = 0;
                assert tmp != null;
                char[] tmpchar = tmp.toCharArray();
                // 寻找起点
                for (int j = 0; j < tmpchar.length; j++) {
                    if(tmpchar[j] == '*'){
                        index = j;
                        break;
                    }
                }
                // 对应四种跳跃情况
                for (int j = 0; j < direction.length; j++) {
                    int nIndex = index + direction[j];
                    if(nIndex < 0 || nIndex >= tmpchar.length){
                        continue;
                    }
                    char[] clone = tmpchar.clone();
                    clone[nIndex] = tmpchar[index];
                    clone[index] = tmpchar[nIndex];

                    String s = new String(clone);
                    if(!set.contains(s)){
                        que.add(s);
                        set.add(s);
                    }
                }
            }
            count++;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        init = scanner.nextLine();
        target = scanner.nextLine();
        bfs();

    }
}
